package ch.fhnw.swa.team42.business;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import ch.fhnw.swa.team42.domain.Person;

@Stateless
public class PersonEJB {
    @PersistenceContext
    private EntityManager em;	
    
    
	public List<Person> findAllPersons() {
        TypedQuery<Person> query = em.createNamedQuery("findAllPersons", Person.class);
        return query.getResultList();
		
	}

	public Person createPerson(Person person) {
        em.persist(person);
        return person;
	}
	
	public Person editPerson(Person person) {
		 return em.merge(person);
	}
	
	public void deletePerson(Person person) {
		 em.remove(em.merge(person));
	}
	
	public Person findPersonByID(Long personID) {
		 return em.find(Person.class, personID);
	}
}
